home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_01 / the.c < prev    next >
C/C++ Source or Header  |  1993-11-15  |  30KB  |  824 lines

  1. /***********************************************************************/
  2. /* THE.C - The Hessling Editor                                         */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1993 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 5314
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38.  
  39. /*
  40. $Header: C:\THE\RCS\the.c 1.4 1993/09/01 16:27:17 MH Interim MH $
  41. */
  42.  
  43. #include <stdio.h>
  44.  
  45. #define MAIN 1
  46. #include "the.h"
  47. #include "proto.h"
  48. #include <signal.h>
  49.  
  50. #if defined(DOS) || defined(OS2)
  51. #  if !defined(EMX) && !defined(GO32)
  52. #    include <direct.h>
  53. #  endif
  54. #endif
  55.  
  56. /*--------------------------- global data -----------------------------*/
  57.  WINDOW *foot,*error_window,*divider;
  58.  VIEW_DETAILS *vd_current=(VIEW_DETAILS *)NULL;
  59.  VIEW_DETAILS *vd_first=(VIEW_DETAILS *)NULL;
  60.  VIEW_DETAILS *vd_mark=(VIEW_DETAILS *)NULL;
  61.  char number_of_views = 0;                          /* number of views */
  62.  char number_of_files = 0;                          /* number of files */
  63.  char display_screens = 1;                        /* number of screens */
  64.  char current_screen = 0;
  65.  SCREEN_DETAILS screen[MAX_SCREENS];            /* 2 screen structures */
  66.  bool horizontal=TRUE;
  67.  short save_coord_x[VIEW_WINDOWS];
  68.  short save_coord_y[VIEW_WINDOWS];
  69.  
  70.  LINE *next_line,*curr_line;
  71.  LINE *first_file_name=NULL,*current_file_name=NULL;
  72.  bool error_on_screen=FALSE;
  73.  bool colour_support=TRUE;         /* indicates if colour is supported */
  74.  char *rec;
  75.  unsigned short rec_len = 0;                          /* length of rec */
  76.  char *cmd_rec;
  77.  unsigned short cmd_rec_len = 0;                  /* length of cmd_rec */
  78.  char *pre_rec;
  79.  unsigned short pre_rec_len = 0;                  /* length of cmd_rec */
  80.  char focus_changed = NO;   /* indicates if focus line has changed */
  81.  char current_changed = NO; /* indicates if current line has changed */
  82.  char mode_insert=NO;           /* defines insert mode toggle */
  83.  char in_profile;          /* indicates if processing profile */
  84.  char execute_profile; /* indicates if we are to process any profile */
  85.  char in_macro;         /* indicates if processing REXX macro */
  86.  char file_read=NO;     /* indicates if we have read the file */
  87.  char curses_started=NO;  /* indicates if cureses has started */
  88.  
  89. #if defined(DOS) || defined(OS2)
  90.  bool extended_display_mode=TRUE;      /* display all 256 characters ? */
  91. #else
  92.  bool extended_display_mode=FALSE;     /* display all 256 characters ? */
  93. #endif
  94.  
  95.  char *the_version = (char *)"1.5";
  96.  char term_name[20];  /* $TERM value */
  97. #if defined(UNIX)
  98.  char user_home_dir[MAX_FILE_NAME+1];
  99. #   define THE_PROFILE_FILE ".therc"
  100. #else
  101. #   define THE_PROFILE_FILE "PROFILE.THE"
  102. #endif
  103.  char *helpfilename = (char *)"THE.HLP";
  104.  char *tempfilename = (char *)"THE.$$$";
  105. #if !defined(NOREXX)
  106.  char *rexxoutname = (char *)"REXX.$$$";
  107.  char rexx_pathname[MAX_FILE_NAME+1];
  108.  char rexx_filename[10];
  109. #endif
  110. #ifdef VMS
  111.  char *dirfilename = (char *)"DIR.THE";
  112. #else
  113.  char *dirfilename = (char *)"DIR.DIR";
  114. #endif
  115.  char macro_suffix[12] = ".the";  /* default extension for macros */
  116.  char dir_pathname[MAX_FILE_NAME+1];
  117.  char dir_filename[10];
  118.  char curr_path[MAX_FILE_NAME+1];
  119.  char sp_path[MAX_FILE_NAME+1];
  120.  char sp_fname[MAX_FILE_NAME+1];
  121.  char dir_path[MAX_FILE_NAME+1];   /* for dir and ls commands */
  122.  
  123.  char the_home_dir[MAX_FILE_NAME+1];
  124.  char the_macro_path[MAX_FILE_NAME+1];   /* for macro command */
  125.  char the_help_file[MAX_FILE_NAME+1];
  126.  char the_profile_file[MAX_FILE_NAME+1];
  127.  
  128.  char *prf_arg=(char *)NULL;
  129.  bool profile_specified=FALSE;
  130.  
  131.  char tabkey_insert='C';
  132.  char tabkey_overwrite='T';
  133.  unsigned short file_start = 36;
  134.  char *last_target;
  135.  
  136. #if defined(UNIX) || defined(OS2)
  137.  char *spooler_name;
  138. #endif
  139.  
  140. char file_disposition;
  141.  
  142. struct stat stat_buf;
  143.  
  144. int reserved_top=0;
  145. int reserved_bottom=0;
  146.  
  147. int lastrc=0;
  148. extern DEFINE *first_define;
  149. #if !defined(NOREXX)
  150. extern LINE *first_prefix_synonym;
  151. #endif
  152. /*---------------------------------------------------------------------*/
  153. /* Following are for getopt function(s).                               */
  154. /*---------------------------------------------------------------------*/
  155. extern char *optarg;
  156. extern int optind;
  157.  
  158. /***********************************************************************/
  159. #ifdef PROTO
  160. int main(int argc, char *argv[])
  161. #else
  162. int main(argc,argv)
  163. int argc;
  164. char *argv[];
  165. #endif
  166. /***********************************************************************/
  167. {
  168. /*-------------------------- external data ----------------------------*/
  169. extern bool CLEARSCREENx;
  170. /*---------------------- function definitions -------------------------*/
  171.  
  172. /*--------------------------- local data ------------------------------*/
  173.  register int i,j,k;
  174.  char *prf=(char *)NULL;
  175.  int c;
  176.  int malloc_fd;
  177.  bool trap_signals=TRUE;
  178.  bool pause_for_errors=FALSE;
  179.  int rc;
  180. /*--------------------------- processing ------------------------------*/
  181. #ifdef __EMX__
  182.  _wildcard(&argc,&argv);
  183. #endif
  184. #ifdef TRACE
  185.  trace_initialise();
  186.  trace_function("the.c:     main");
  187. #endif
  188. /*---------------------------------------------------------------------*/
  189. /* Set up flag to indicate that we are not interactive...yet.          */
  190. /*---------------------------------------------------------------------*/
  191.  in_profile = TRUE;
  192.  execute_profile = TRUE;
  193.  in_macro = FALSE;
  194. /*---------------------------------------------------------------------*/
  195. /* Initialise the printer spooler.                                     */
  196. /*---------------------------------------------------------------------*/
  197. #if defined(UNIX) || defined(OS2)
  198.  if ((spooler_name = (char *)malloc(4*sizeof(char))) == NULL)
  199.    {
  200.     display_error(30,(char *)"");
  201.     exit_clean(1);
  202.    }
  203. #  ifdef UNIX
  204.  strcpy(spooler_name,(char *)"lpr");
  205. #  else
  206.  strcpy(spooler_name,(char *)"LPT1");
  207. #  endif
  208. #endif
  209. /*---------------------------------------------------------------------*/
  210. /* Get all environment variables here. Some may be overridden by       */
  211. /* command-line switches. (future possibility)                        */
  212. /*---------------------------------------------------------------------*/
  213. #if defined(UNIX)
  214.  if (getenv("HOME") != NULL)
  215.     strcpy(user_home_dir,getenv("HOME"));
  216.  else
  217.     strcpy(user_home_dir,"./");
  218.  if (*(user_home_dir+strlen(user_home_dir)-1) != ISLASH)
  219.     strcat(user_home_dir,ISTR_SLASH);
  220.  if (getenv("TERM") != NULL)
  221.     strcpy(term_name,getenv("TERM"));
  222.  else
  223.     strcpy(term_name,"default");
  224. #endif
  225. #if defined(DOS)
  226.  strcpy(term_name,"DOS");
  227. #endif
  228. #if defined(OS2)
  229.  strcpy(term_name,"OS2");
  230. #endif
  231. /*---------------------------------------------------------------------*/
  232. /* Get THE_HOME_DIR first (as all other paths rely on this value)      */
  233. /*---------------------------------------------------------------------*/
  234.  if (getenv("THE_HOME_DIR") != NULL)
  235.    {
  236.     strcpy(the_home_dir,getenv("THE_HOME_DIR"));
  237.     (void *)strtrans(the_home_dir,OSLASH,ISLASH);
  238.     if ((the_home_dir[strlen(the_home_dir)-1]) != ISLASH)
  239.        strcat(the_home_dir,